package com.mingqijia.gassafety.shared.utils;

import com.mingqijia.gassafety.shared.constant.Constants;

public class TimeUtil {


    /**
     * 秒数转中文描述 XX天XX小时XX分钟
     * @param second
     * @return
     */
    public static String secondToStr(final Long second) {
        if (second == null || second <= 0) {
            return Constants.BLANK;
        }else if (second > 0 && second < 60) {
            return "1分钟";
        } else {
            StringBuffer sb = new StringBuffer(Constants.BLANK);
            // 计算天数
            long days = second / 86400;
            // 剩余秒数
            long remainingSeconds = second % 86400;
            // 计算小时数
            long hours = remainingSeconds / 3600;
            // 剩余秒数
            long remainingAfterHours = remainingSeconds % 3600;
            // 计算分钟数
            long minutes = remainingAfterHours / 60;
            if (days > 0) {
                sb.append(days).append("天");
            }
            if (hours > 0) {
                sb.append(hours).append("小时");
            }
            if (minutes > 0) {
                sb.append(minutes).append("分钟");
            }
            return sb.toString();
        }

    }

}
